package com.gxm.面试.线程;

import org.junit.Test;

public class 两代码区别_中间值 {

    private int count = 0;

    private int getSum1(){
        for (int i = 0; i < 1000; i++) {
            count++;
        }
        return count;
    }

    private int getSum2(){
        int tmp = 0;
        for (int i = 0; i < 1000; i++) {
            tmp++;
        }
        count = tmp;
        return count;
    }

    /**
     * getSum1 中 count 存在多次 中间值,
     * 与getSum2 相比 多线程调用时 线程同步问题 更严重
     */
    @Test
    public void demo(){
        System.out.println(getSum1());
        System.out.println(getSum2());
    }
}
